/**
  ******************************************************************************
  * @file    rs485.c
  * @brief   This file provides code for the configuration
  *          of the RS485 instances.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "rs485.h"


/* Defines -------------------------------------------------------------------*/

/* Variables -----------------------------------------------------------------*/

/* Prototypes ----------------------------------------------------------------*/
void RS485_SendCtrl(void)
{
	GpioDataRegs.GPBSET.bit.RS485_DE_RE_PIN =1;
}

void RS485_RecvCtrl(void)
{
	GpioDataRegs.GPBCLEAR.bit.RS485_DE_RE_PIN =1;
}
void RS485_Init(void)
{
	EALLOW;
	GpioCtrlRegs.GPBMUX1.bit.RS485_DE_RE_PIN =0;
	GpioCtrlRegs.GPBDIR.bit.RS485_DE_RE_PIN = 1;
	EDIS;
	RS485_RecvCtrl();

}

void RS485_SendData(char*buff,int len)
{
	int WaitTimer = 0;
	RS485_SendCtrl();
	SciSendString(buff,len);
	while(SciaRegs.SCICTL2.bit.TXEMPTY != 1)
	{
		WaitTimer++;
		if(WaitTimer > (Uint16)10*(60000000L/115200L)) break;
	}
	RS485_RecvCtrl();
}


